<script type="text/javascript">
	function doSearchResource(value) {
		
	}
	
	//表格查询  
	function reloadResource() {
		var params = resource_list.datagrid('options').queryParams; //先取得 datagrid 的查询参数  
		printLog(params);
		resource_list.datagrid('reload'); //设置好查询参数 reload 一下就可以了  
		resource_list.datagrid('unselectAll');
		resource_list.datagrid('uncheckAll');
	}


	function addResource() {
// 		createFromWindow("新增信息", "resource.do?editResource", "resource.do?saveResource",
// 				function(data) {
// 					reloadResource();
// 				});
		createFromWindowOptions({
			title:"新增信息",
			width:1000,
			maximizable:true,
			href:"resource.do?editResource",
			callback:function(data) {
				printLog(data);
				saveResoucePermissionInfo();
			},
			enableSaveButton:true
		});
	}
	
	function deleteResource() {
		var rows = resource_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('resource.do?deleteResourceItems',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadResource();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}

	function editResource() {
		var rows = resource_list.datagrid('getChecked');
		printLog(rows);
		if (rows&&rows.length>0) {
			if(rows.length>1) {
				showMsg('请选择一条操作记录.');
				return;
			}
// 			createFromWindow("编辑信息", "resource.do?editResource&resourceId=" + rows[0].id,
// 					"resource.do?saveResource", function(data) {
// 						reloadResource();
// 					},true);
			createFromWindowOptions({
				title:"编辑信息",
				maximizable:true,
				width:1000,
				href:"resource.do?editResource&resourceId=" + rows[0].id,
				callback:function(data) {
					printLog(data);
					saveResoucePermissionInfo();
				},
				enableSaveButton:true
			});
		} else {
			showMsg('请选择操作记录.');
		}

	}
	
	
	//操作按钮触发
	function operationsLookResource(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = resource_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindow("查看信息", "resource.do?editResource&resourceId=" + id,
					null, null,false);
		} else {
			showMsg('请选择查看记录.');
		}
	}
	
	function operationsEditResource(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = resource_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindow("编辑信息", "resource.do?editResource&resourceId=" + id,
					"resource.do?saveResource", function(data) {
						reloadResource();
					},true);
		} else {
			showMsg('请选择编辑记录.');
		}
	}
	
	function operationsSendResource() {
		printLog('发送');
	}
	
	function operationsDeleteResource(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = new_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			$.messager.confirm('询问', '你确认要删除吗?', function(r) {
				if (r) {
					$.post('resource.do?deleteResourceItems', {
						ids : id
					}, function(result) {
						if (result.success) {
							reloadResource(); 
						}
						showMsg(result.msg);
					}, 'json');
				}
			});
		} else {
			showMsg("请选择操作记录.");
		}
	}
</script>

<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
		
		<@eu.datagrid id="resource_list" toolbar="#resourcelist_search" idField="id" 
			 url="resource.do?loadList" rownumbers="true"
			 item="com.xdtech.sys.vo.ResourceItem"/>
		
		<div id="resourcelist_search">
			<div id="resource_toolbar" style="height: auto">
				
				<@eu.linkbutton showName="新增" shiro="sys:resource:add" iconCls="icon-add" onclick="addResource()"/>
				<@eu.linkbutton showName="删除" shiro="sys:resource:delete" iconCls="icon-remove" onclick="deleteResource()"/>
				<@eu.linkbutton showName="编辑" shiro="sys:resource:edit" iconCls="icon-edit" onclick="editResource()"/>
				<@eu.linkbutton showName="刷新" shiro="sys:resource:refresh" iconCls="icon-reload" onclick="reloadResource()"/>
				
			</div>
		</div>
	</div>
</div>